﻿
using Dapper;
using HBase; 
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace hCommand
{

    public class AreaGroup2LocEngine<CS> : AbsLocEngine where CS : AbsCoreStock  {

        public long paramId = 0;



        protected override TransRes Execute(IDbConnection conn ,IDbTransaction trans) {
            CoreTaskParam param = conn.GetById<CoreTaskParam>(paramId ,trans);
            CoreTask ct = conn.GetById<CoreTask>(param.taskId ,trans);
            CoreWhGroup group = conn.GetById<CoreWhGroup>(param.des ,trans);
            CS cs = conn.GetById<CS>(ct.stockId, trans);
            if ( group == null ) {
                return new TransRes();
            }
            string sql = "select * from Core_Wh_Loc where  Active_Status in (0,2) and  area_id =@areaId  and move_group=@locGroup  order by order_No";
            List<CoreWhLoc> locList = conn.Query<CoreWhLoc>(sql ,group ,trans).ToList();

            CoreWhLoc coreWhLoc = I18nConfig.select(locList ,-1,cs);
            if( coreWhLoc == null ) {
                return new TransRes();
            }
            String updateSql = "update Core_Task_Param  set des=@des ,status=@status where id=@id";
            conn.Execute(updateSql ,new { des = ( int ) coreWhLoc.id ,status = ( int ) CoreTaskParamStatus.可以接收任务 ,id = param.id } ,trans);


            ct.des = ( int ) coreWhLoc.id;
            ct.info += "-" + ct.des;
            conn.Execute("update core_task set des=@des,info=@info where id=@id" ,ct ,trans);

            UpdataWhLoc(conn ,trans ,coreWhLoc.id ,ct.goodDiff);
            return new TransRes();
        }


    }
}
